﻿using System;
using System.Collections.Generic;
using System.Data.Linq;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Ex06
{
    class Program
    {
        static void Main(string[] args)
        {
            var db = new NorthwindDataContext();
            // In this example we're using DataLoadOptions for eager loading. Notice that only
            // one SQL query now shows in the SQL results pane, despite using nested foreach
            // loops to enumerate the results:

            var options = new DataLoadOptions();
            options.LoadWith<Customer>(c => c.Purchases);

            // Uncomment the following line to specify a filter as well:
            options.AssociateWith<Customer>(c => c.Purchases.Where(p => p.Price > 1000));

            db.LoadOptions = options;

            foreach (Customer c in db.Customers)
            {
                Console.WriteLine(c.ID + " " + c.Name);
                foreach (Purchase p in c.Purchases)
                    Console.WriteLine("  - purchased a " + p.Description);
            }
            Console.ReadKey();
        }
    }
}
